#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#       util.py
#       
#       Copyright 2012 José Roberto Colombo Junior <junior@Hohenheim>
#       
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later version.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.

def list2str(lista):
	string = ''
	for item in lista:
		string+=str(item)+' '
		
	return string

def setar_caixa_tempo (item):
	if item == 's':
		return 0
	
	if item == 'ms':
		return 1
	
	if item == 'us':
		return 2
	
	if item == 'ns':
		return 3
	
	if item == 'ps':
		return 4

def caixa_tempo (item):
	if item == 0:
		return 's '
	
	if item == 1:
		return 'ms '
	
	if item == 2:
		return 'us '
	
	if item == 3:
		return 'ns '
	
	if item == 4:
		return 'ps '

def caixa_frequencia (item):
	if item == 0:
		return 'Hz '
	
	if item == 1:
		return 'kHz '
	
	if item == 2:
		return 'MHz '
	
	if item == 3:
		return 'GHz '
	
	if item == 4:
		return 'THz '

def setar_caixa_frequencia (item):
	if item == 'Hz':
		return 0
	
	if item == 'kHz':
		return 1
	
	if item == 'MHz':
		return 2
	
	if item == 'GHz':
		return 3
	
	if item == 'THz':
		return 4
		
def caixa_operacao (item, noh):
	if (item == 0) or (item == 1):
		return '(' + noh + ')'
	
	if item == 2:
		return 'mag(' + noh + ')'
	
	if item == 3:
		return 'db(' + noh + ')'
	
	if item == 4:
		return 'ph(' + noh + ')'
		
	if item == 5:
		return 'real(' + noh + ')'
	
	if item == 6:
		return 'imag(' + noh + ')'

def setar_caixa_operacao (item):
	if item == '':
		return 1
	
	if (item == 'mag') or (item == 'abs'):
		return 2
	
	if item == 'db':
		return 3
	
	if item == 'ph':
		return 4
		
	if item == 'real':
		return 5
	
	if item == 'imag':
		return 6

def noh_(item, noh):
	if item == 0:
		return 'v(' + noh + ')'
	
	if item == 1:
		return 'i(' + noh + ')'

def setar_decada(item):
	if item == 'DEC':
		return 0
		
	if item == 'LIN':
		return 1
		
	if item == 'OCT':
		return 2

def decada (item):
	if item == 0:
		return 'DEC '
	
	if item == 1:
		return 'LIN '
		
	if item == 2:
		return 'OCT '

def spice_include():
	texto = "\nC 37900 50300 1 0 0 spice-include-1.sym\
\n{\
\nT 38000 50600 5 10 0 1 0 0 1\
\ndevice=include\
\nT 38000 50700 5 10 1 1 0 0 1\
\nrefdes=PySP1\
\nT 38400 50400 5 10 1 1 0 0 1\
\nfile=./simulation.cmd\n}"
	return texto
